Skip to content

Improve frame interpolation#4919

Merged
Loobinex merged 32 commits into
dkfans:masterfrom
jwt27:lerp
Jul 5, 2026
Merged

Improve frame interpolation#4919
Loobinex merged 32 commits into
dkfans:masterfrom
jwt27:lerp

Conversation

@jwt27

@jwt27 jwt27 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

The frame interpolation method used is non-linear and includes some future-prediction, which causes overshoots. #4908 works around the visual effect, but I believe it is better to use a purely linear method instead.

This did uncover some new bugs, where the previous-frame position was reset too early. Those have been fixed now.

I removed the minimap interpolation code, as it was not necessary. Both the (local) camera and all Things already have interpolated map positions, there is no need to do it twice.

@jwt27 jwt27 changed the title Use linear frame interpolation Improve frame interpolation Jun 14, 2026
@jwt27 jwt27 marked this pull request as ready for review June 16, 2026 17:50
@jwt27 jwt27 marked this pull request as draft June 16, 2026 18:03
@jwt27 jwt27 marked this pull request as ready for review June 16, 2026 18:03
@Loobinex Loobinex requested a review from rainlizard June 16, 2026 18:44
@jwt27 jwt27 marked this pull request as draft June 16, 2026 18:54
@jwt27 jwt27 marked this pull request as ready for review June 16, 2026 18:54
@jwt27 jwt27 marked this pull request as draft June 16, 2026 21:32
@jwt27 jwt27 marked this pull request as ready for review June 16, 2026 21:33
@jwt27 jwt27 marked this pull request as draft June 20, 2026 13:02
@jwt27 jwt27 marked this pull request as ready for review June 20, 2026 13:02
Makes the mouse light a little less flickery.
@jwt27 jwt27 marked this pull request as draft June 21, 2026 01:06
@jwt27 jwt27 marked this pull request as ready for review June 22, 2026 15:48
Clean up this function and match logic with get_player_coords_and_context()
in front_input.c.

Fixes local mouse light glitching when:
- something is held in hand, and there is something under it to pick up
- pointing just above/behind a door (DoorKey cursor state)
@jwt27

jwt27 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

To reiterate, this is stuck because it doesn't play nice with 0-turns input lag in multiplayer. Or maybe, exposes existing problems with it, which the current interpolation method is better able to hide :)

Video frames now must be drawn with process_turn_time exactly in [0.0, 1.0], to avoid extrapolating or stuttering. But when waiting for network packets, additional frames are drawn outside this interval. In principle, this could be solved by these 3 commits. This handles packet exchange 1 video frame before the next turn.

Then however, another problem becomes apparent, which is that the client clock drifts. This causes the perceived latency to increase, and so it spends more time waiting and drawing stale frames. The reason is that clock sync (speed adjustment) depends on the round-trip timing measured by the ENet library, but this is inaccurate, because network messages are only sent and received once per turn. So the measured RTT is the sum of:

  • the real network latency
  • sometimes, an extra 50ms turn delay
  • the already-accumulated clock drift (feedback loop)

To solve this, I think network packets need to be answered in real-time, on a separate thread. I expect this involves some large restructuring that I'd rather not jump into, right now. Alternatively, maybe some other way of turn synchronizing can be found that doesn't rely on RTT at all. Eg. clients could adjust their clock based on when they receive a packet from the host.

@Loobinex Loobinex marked this pull request as draft June 30, 2026 17:55
Comment thread src/engine_render.c Outdated
Comment thread src/net_exchange_gameplay.c
Comment thread src/main.cpp Outdated
Comment on lines +3429 to +3435
if (is_feature_on(Ft_DeltaTime))
{
frametime_start_measurement(Frametime_Sleep);
if (turns_per_second_draw_current > 0)
keeper_wait_for_next_draw();
frametime_end_measurement(Frametime_Sleep);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I moved the fps limiter to gameplay_loop_draw(). But now I think it could interfere with multiplayer timing here. On the other hand, if the limiter is only active in the normal gameplay loop but not during packet exchange, then average_delta_time becomes useless. May need to think some more about this.

@jwt27 jwt27 marked this pull request as ready for review July 4, 2026 21:10
@jwt27 jwt27 requested a review from rainlizard July 4, 2026 21:10
@Loobinex Loobinex merged commit 71d01be into dkfans:master Jul 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants